﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ReceiptTracker
{
    public partial class FormViewReceipts : Form
    {
        private SQLiteDB db;
        private DataTable dt = new DataTable();
        public FormViewReceipts(SQLiteDB db)
        {
            InitializeComponent();
            this.db = db;
            GetReceipts();
            dataGridView.DataSource = dt;
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void GetReceipts()
        {
            db.SQLQuery("SELECT date,spent,Shops.name AS Shop,Categories.name AS Category FROM Receipts,Shops,Categories WHERE Receipts.shop= Shops.id AND Shops.category=Categories.Id;");
            dt.Clear();
            dt.Merge(db.QueryResult);
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            GetReceipts();
        }
    }
}
